package com.example.wlf.gamerecorder.gameon;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.wlf.gamerecorder.R;
import com.example.wlf.gamerecorder.Constants;
public class SettingActivity extends AppCompatActivity {

    private EditText editTextHost;
    private EditText editTextGuest;
    String homeTeamName;
    String guestTeamName;
    private static boolean hasSettingPeriod = false;
    @Override
    public void onBackPressed() {
        //Do Nothing
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setting);
        final TextView textViewSetting12 = (TextView)findViewById(R.id.textViewSetting12);
        final TextView textViewSetting10 = (TextView)findViewById(R.id.textViewSetting10);
        //TextView textViewTimeMinute = (TextView)findViewById(R.id.textViewTimeMinute);
        textViewSetting12.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Constants.stringToTime("12:00","mm:ss");
                textViewSetting12.setTextColor(Color.GREEN);
                textViewSetting10.setTextColor(Color.BLACK);
                Intent intent = new Intent();
                intent.putExtra("int",720);//12*60sec
                intent.putExtra("string","12:00");
                setResult(RESULT_OK,intent);
                hasSettingPeriod = true;
                //finish();
            }
        });

        textViewSetting10.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                textViewSetting10.setTextColor(Color.GREEN);
                textViewSetting12.setTextColor(Color.BLACK);
                Intent intent = new Intent();
                intent.putExtra("int",600);//10*60sec
                intent.putExtra("string","10:00");
                setResult(RESULT_OK,intent);
                hasSettingPeriod = true;
                //finish();
            }
        });
        findViewById(R.id.button_save_gamesetting).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!hasSettingPeriod){
                    showToast();
                }
                else{
                    editTextHost = (EditText)findViewById(R.id.EditTextHoseTeam);
                    homeTeamName = editTextHost.getText().toString();
                    editTextGuest = (EditText)findViewById(R.id.EditTextGuestTeam);
                    guestTeamName = editTextGuest.getText().toString();
                    if(homeTeamName.isEmpty())//如果没有设置主队
                        SimpleGameonActivity.lblTitle1.setText("主队");
                    else
                        SimpleGameonActivity.lblTitle1.setText(homeTeamName);

                    if(guestTeamName.isEmpty())//如果没有设置主队
                        SimpleGameonActivity.lblTitle2.setText("客队");
                    else
                        SimpleGameonActivity.lblTitle2.setText(guestTeamName);

                    finish();
                }

            }
        });

    }
   // public void setPeriodValue(Intent intent,)
   public void showToast(){
       Toast.makeText(this,"请先设置比赛信息！",Toast.LENGTH_SHORT).show();
   }
}
